Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Handle pipe names with whitespace properly #2409

Merged
merged 1 commit into from
Jun 19, 2018

Conversation

ajaybhargavb
Copy link
Contributor

@ajaybhargavb ajaybhargavb commented Jun 15, 2018

Fixes #2406

The actual bug here was that I was not passing the pipe name in the process arguments within quotes 🤦‍♂️

  • Added an integration test to verify this fix
  • Added more logging to make sure command parsing errors gets logged

@mkArtakMSFT FYI

@@ -290,7 +290,7 @@ internal static bool TryCreateServerCore(string clientDir, string pipeName, out
// The server should be in the same directory as the client
var expectedCompilerPath = Path.Combine(clientDir, ServerName);
expectedPath = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH") ?? "dotnet";
processArguments = $@"""{expectedCompilerPath}"" {(debug ? "--debug" : "")} server -p {pipeName}";
processArguments = $@"""{expectedCompilerPath}"" {(debug ? "--debug" : "")} server -p ""{pipeName}""";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😢

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there other places we manually start a process? Can you double check?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you double check?

Just did. There is just this and tests.

Should we use https://github.com/aspnet/Common/blob/dev/shared/Microsoft.Extensions.CommandLineUtils.Sources/Utilities/ArgumentEscaper.cs#L24?

I'm not sure actually. I did a quick check and looks like we only use it mostly in BuildTools. Was it intended for using in product code?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you can use it in product code. We use it in dotnet-watch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Primarily suggesting this since this includes values constructed from user data. There could be other things we might be missing whilst doing double-quote escaping.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if this project is using the netcoreapp2.1 TFM or higher, use ProcessStartInfo.ArgumentList instead of ProcessStartInfo.Arguments. See for example https://github.com/natemcmaster/dotnet-serve/blob/dac796c44c1c4b7ef101763c60e4d7ddfc3cd2d6/test/dotnet-serve.Tests/DotNetServe.cs#L101-L148.


// This will no-op if server logging is not enabled.
ServerLogger.Log(output);
ServerLogger.Log(error);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've already something similar for the code path when the server is already started. But I missed logging this code path which gets called during the server start.

@@ -46,7 +46,7 @@ static ServerLogger()
// Otherwise, assume that the environment variable specifies the name of the log file.
if (Directory.Exists(loggingFileName))
{
loggingFileName = Path.Combine(loggingFileName, $"server.{loggingFileName}.{GetCurrentProcessId()}.log");
loggingFileName = Path.Combine(loggingFileName, $"razorserver.{GetCurrentProcessId()}.log");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change lets me specify absolute path for directories here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -54,18 +58,5 @@ public void Dispose()
}
}
}

private static string RecursiveFind(string path, string start)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused

@ajaybhargavb
Copy link
Contributor Author

🆙 📅

@@ -16,17 +17,31 @@ public static int Main(string[] args)
var cancel = new CancellationTokenSource();
Console.CancelKeyPress += (sender, e) => { cancel.Cancel(); };

var outputWriter = new StringWriter();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: the StringWriter is disposable, so should be wrapped with a using statement. However, this is in the main method, which means when it's unused, the process will exit and all the resources will be cleaned up anyway.

@ajaybhargavb ajaybhargavb force-pushed the ajbaaska/pipe-name-space branch from 68ab62a to 6497942 Compare June 19, 2018 21:54
@ajaybhargavb ajaybhargavb force-pushed the ajbaaska/pipe-name-space branch from 6497942 to 17e3aa8 Compare June 19, 2018 22:11
@ajaybhargavb ajaybhargavb merged commit 17e3aa8 into dev Jun 19, 2018
@ajaybhargavb ajaybhargavb deleted the ajbaaska/pipe-name-space branch June 19, 2018 22:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants